**************************************************
*Yuhua Wang*
*The Rise and Fall of Imperial China: The Social Origins of State Development*
*Princeton University Press, 2022*
**************************************************

**************************************************
*Appendices*
**************************************************

**************************************************
*Table A.1: Temperature Anomalies and Conflict: OLS Estimates*
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "temperature and conflict.dta", clear

*Organize the data in decades*

keep if year>=1 & year<=1910

gen decade = floor((year-1)/10)
order decade

bys decade: egen war_d = sum(allwar)
bys decade: egen externalwar_d = sum(externalwar)
bys decade: egen internalwar_d = sum(internalwar)
bys decade: egen peasantreb_d  = sum(peasantreb)
bys decade: egen elitereb_d = sum(elitereb)

sort decade year
by decade: carryforward temp*, replace
gsort decade -year
by decade: carryforward temp*, replace

duplicates drop decade, force
drop year

label var temppls "Temperature anomaly (degree Celsius)"
label var externalwar_d "Number of external wars"
label var peasantreb_d "Number of mass rebellions"

tsset decade

*Results*

xi:reg externalwar_d temppls, robust
estimates store temp1
estadd ysumm

xi:reg externalwar_d L.externalwar_d temppls, robust
estimates store temp2
estadd ysumm

xi:reg peasantreb_d temppls, robust
estimates store temp3
estadd ysumm

xi:reg peasantreb_d L.peasantreb_d temppls, robust
estimates store temp4
estadd ysumm

esttab temp1 temp2 temp3 temp4 using tempmodel.tex, replace fragment ///
    keep(temppls L.externalwar_d L.peasantreb_d) ///
	order(temppls L.externalwar_d L.peasantreb_d) ///
    b(3) se(3) posthead(\cmidrule(lr){2-5}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2"))

**************************************************
*Table C.1: Summary Statistics for Dataset in Chapter 5*
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Wang Anshi reform data_wk.dta",clear

global y "support_continuous newparty"
global x "kinproximity"
global controls "betweenness degree bonacich kin_node children supportfaction kinmedianexposuretoexternal50 kinmedianexposuretointernal50 avg_ruggedness father_exam uncle_any_exam grandfather_official dist_grandfather_father"

*Whole sample*

estpost sum  $y $x $controls

esttab using sumstats_whole.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace
	

**************************************************
*Table C.2: Political Selection and Geography of Kinship Network: OLS Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Wang Anshi reform data_wk.dta",clear

local controls1 "i.hometown_prefecture_id"
local controls2 "uncle_any_exam i.hometown_prefecture_id"
local controls3 "uncle_any_exam grandfather_official i.hometown_prefecture_id"

xi: reg kinproximity father_exam `controls1',cl(hometown_prefecture_id)
estimates store fathermodel1
estadd ysumm

xi: reg kinproximity father_exam `controls2',cl(hometown_prefecture_id)
estimates store fathermodel2
estadd ysumm

xi: reg kinproximity father_exam `controls3',cl(hometown_prefecture_id)
estimates store fathermodel3
estadd ysumm

esttab fathermodel1 fathermodel2 fathermodel3 using fathermodel.tex, ///
	replace fragment keep(father_exam uncle_any_exam grandfather_official) ///
	b(3) se(3) posthead(\cmidrule(lr){2-4}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("Prefectural FE = *Ihometown*")
	
**************************************************
*Table C.3: Local Concentration of Kin and Support for Reform: OLS Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Wang Anshi reform data_wk.dta",clear

local controls0 ""
local controls1 "i.hometown_prefecture_id"
local controls2 "betweenness kin_node children supportfaction kinmedianexposuretoexternal50 kinmedianexposuretointernal50  avg_ruggedness father_exam dist_grandfather_father i.hometown_prefecture_id"

xi: reg support_continuous kinproximity,cl(hometown_prefecture_id)
estimates store benchmarkmodel1
estadd ysumm

xi: reg support_continuous kinproximity `controls1',cl(hometown_prefecture_id)
estimates store benchmarkmodel2
estadd ysumm

xi: reg support_continuous kinproximity `controls2',cl(hometown_prefecture_id)
estimates store benchmarkmodel3
estadd ysumm

esttab benchmarkmodel1 benchmarkmodel2 benchmarkmodel3 using benchmarkmodel.tex, ///
	replace fragment keep(kinproximity) ///
	b(3) se(3) posthead(\cmidrule(lr){2-4}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	 label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)" ) sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("Betweenness centrality = betweenness" "N of kin=kin_node" "N of children=children" "Factional tie with reform leader=supportfaction" "Kin centroid exposure to external wars=kinmedianexposuretoexternal50" "Kin centroid exposure to mass rebellions=kinmedianexposuretointernal50" "Ruggedness Index=avg_ruggedness" "Father passing exam=father_exam" "Father migration=dist_grandfather_father" "Prefecture FE = *Ihometown_*")

**************************************************
*Table D.1: Summary Statistics for Dataset in Chapter 6
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Single Whip Reform data.dta"

estpost sum politician presentedscholar_pre1573 timeatrisk timeatrisk_prov_pref timeatrisk_prov_pref_county ///
implementation implementation_prov_pref implementation_prov_pref_county

esttab using sumstatssinglewhip.tex, modelwidth(15 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace

	
**************************************************
*Figure D.2: Estimated Survival and Hazard Functions of Prefectures With and Without At Least One Major Official
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Single Whip Reform data.dta"

***Estimated survival function***

stset timeatrisk, failure(implementation)
stcox  politician_dummy i.province_id, shared(province_id)

stcurve, saving(survival, replace) survival at1(politician_dummy=1) at2(politician_dummy=0) range (0 90) ///
clwidth(medthick medthick) clcolor(red blue) ///
      clpattern(solid dash) ///
xtitle("Years Taken Since 1531 to Implement Single Whip")  ytitle("Survival of Status Quo") title("") ///
graphregion(color(white) icolor(white)) plotregion(color(white) icolor(white)) ///
legend(label(1 "At Least One Major Official") label(2 "No Major Officials"))

***Estimated hazard function***

stset timeatrisk, failure(implementation)
stcox  politician_dummy i.province_id, shared(province_id)

stcurve, saving(hazard, replace) hazard at1(politician_dummy=1) at2(politician_dummy=0) range (0 90) ///
clwidth(medthick medthick) clcolor(red blue) ///
      clpattern(solid dash) ///
xtitle("Years Taken Since 1531 to Implement Single Whip")  ytitle("Smoothed Hazard Function") title("") ///
graphregion(color(white) icolor(white)) plotregion(color(white) icolor(white)) ///
legend(label(1 "At Least One Major Official") label(2 "No Major Officials"))

graph combine survival.gph hazard.gph, saving("singlewhipimplement.pdf", replace) scheme(s2color) col(1)  graphregion(fcolor(white))

graph export singlewhipimplement.pdf, as(pdf) replace
cap graph close graph

**************************************************
*Table D.3: National Representation and Delay in Adopting the Single Whip: Survival Analysis
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Single Whip Reform data.dta"

*Column 1: Considering implementation only at the prefectual level

stset timeatrisk, failure(implementation)

stcox politician, shared(province_id)
estimates store singlewhipmodel1
estadd ysumm

stcox politician i.province_id, shared(province_id)
estimates store singlewhipmodel2
estadd ysumm

*Column 2: Considering implementation at the provincial and prefectual levels

stset timeatrisk_prov_pref, failure(implementation_prov_pref)

stcox politician, shared(province_id)
estimates store singlewhipmodel3
estadd ysumm

stcox politician i.province_id, shared(province_id)
estimates store singlewhipmodel4
estadd ysumm

*Column 3:  Considering implementation at the provincial, prefectual, and county levels

stset timeatrisk_prov_pref_county, failure(implementation_prov_pref_county)

stcox politician, shared(province_id)
estimates store singlewhipmodel5
estadd ysumm

stcox politician i.province_id, shared(province_id)
estimates store singlewhipmodel6
estadd ysumm

esttab singlewhipmodel1 singlewhipmodel2 singlewhipmodel3 singlewhipmodel4 singlewhipmodel5 singlewhipmodel6 using singlewhipmodel.tex, replace fragment keep(politician) ///
    b(3) se(3) posthead(\cmidrule(lr){2-7}) ///
	eform cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N, fmt(3 3 0) labels("Outcome mean" "Outcome std.dev." "Observations")) ///
	indicate("Provincial FE = *province_id")

**************************************************
*Table D.4: Advanced Scholars and Major Officials: OLS Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Single Whip Reform data.dta"

xi: reg politician presentedscholar_pre1573, cl(province_id)
estimates store examofficialmodel1
estadd ysumm

xi: reg politician presentedscholar_pre1573 i.province_id, cl(province_id)
estimates store examofficialmodel2
estadd ysumm

esttab examofficialmodel1 examofficialmodel2 using examofficialmodel.tex, ///
	replace fragment keep(presentedscholar_pre1573) ///
	b(3) se(3) posthead(\cmidrule(lr){2-3}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	 label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)" ) sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("Provincial FE = *_Iprovince_*")

**************************************************
*Table E.1: Summary Statistics for Dataset in Chapter 7
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "lineage cross section.dta"

global y "clans clans_IHS genealogy genealogy_IHS"
global geographic_controls "latitude longitude shape_area elevation slope dist_rivers_log rice_ir pop_den_1820 garrison_count quota"
global historical_controls "jinshi_earlyqing conflicts_earlyqing"
global historical_controls_IHS "jinshi_earlyqing_IHS conflicts_earlyqing_IHS"

estpost sum  $y $geographic_controls $historical_controls $historical_controls_IHS

esttab using sumstatslineage.tex, modelwidth(15 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace

	
**************************************************
*Table E.2: Exam Success, Violence, and Lineage Organizations: OLS Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "lineage cross section.dta"	

local prefecture_fe "i.prefecturename_chi"
local geographic_controls "latitude longitude shape_area elevation slope dist_rivers_log rice_ir garrison_count pop_den_1820 quota"
local qing_controls_IHS "jinshi_earlyqing_IHS conflicts_earlyqing_IHS"
local qing_controls "jinshi_earlyqing conflicts_earlyqing"

xi:reg clans `qing_controls', cl(prefecturename_chi)
estimates store clan1
estadd ysumm

xi:reg clans `qing_controls' `geographic_controls' `prefecture_fe', cl(prefecturename_chi)
estimates store clan2
estadd ysumm

xi:reg clans_IHS `qing_controls_IHS' `geographic_controls' `prefecture_fe', cl(prefecturename_chi)
estimates store clan3
estadd ysumm

xi:reg genealogy `qing_controls', cl(prefecturename_chi)
estimates store clan4
estadd ysumm

xi:reg genealogy `qing_controls' `geographic_controls' `prefecture_fe', cl(prefecturename_chi)
estimates store clan5
estadd ysumm

xi:reg genealogy_IHS `qing_controls_IHS' `geographic_controls' `prefecture_fe', cl(prefecturename_chi)
estimates store clan6
estadd ysumm

esttab clan1 clan2 clan3 clan4 clan5 clan6 using clanmodel.tex, replace fragment ///
    keep(jinshi_earlyqing conflicts_earlyqing jinshi_earlyqing_IHS conflicts_earlyqing_IHS) ///
    b(3) se(3) posthead(\cmidrule(lr){2-7}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("Controls=latitude" "Prefecture FE = *Iprefectur*")
	
**************************************************
*Table F.1: Summary Statistics for Dataset in Chapter 8
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off

use "Late Qing data.dta", clear

estpost sum genealogy genealogy_IHS if periodid==1

esttab using taipingsumdid1.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace
	
estpost sum genealogy genealogy_IHS if periodid==2

esttab using taipingsumdid2.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace
	
estpost sum genealogy genealogy_IHS if periodid==3

esttab using taipingsumdid3.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace
	
estpost sum genealogy genealogy_IHS massrebellion if periodid==5

esttab using taipingsumdid4.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace

estpost sum independence genealogy_IHS quota ///
x y shape_area dist_beijing_log dist_rivers_log dist_coast_log pass_qing_courier ///
elevation slope pop_den_1820 rice_ir if periodid==6

esttab using qingsumstats.tex, modelwidth(10 10 20 20 20) cell((count(label(N)) ///
	mean(fmt(3) label(Mean)) sd(fmt(3) label(Standard Deviation)) min(fmt(3) label(Min.)) max(fmt(3) label(Max.)))) ///
	plain noobs label nomtitle nonumber replace
	
**************************************************
*Table F.2: Mass Rebellion and Lineage Activity: Difference-in-Differences Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off
	
use "Late Qing data.dta", clear

xi: reg genealogy_IHS period2_massrebellion period2 i.countyid if periodid==1 | periodid==2,cl(countyid)
estimates store commontrend1
estadd ysumm

xi: reg genealogy_IHS period3_massrebellion period3 i.countyid if periodid==2 | periodid==3,cl(countyid)
estimates store commontrend2
estadd ysumm

xi: reg genealogy_IHS post_massrebellion post i.countyid if periodid==3 | periodid==5,cl(countyid)
estimates store taiping
estadd ysumm

esttab commontrend1 commontrend2 taiping using taiping.tex, ///
	replace fragment keep(period2_massrebellion period3_massrebellion post_massrebellion) ///
	b(3) se(3) posthead(\cmidrule(lr){2-4}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("County FE = *countyid*" "Period FE = post period2 period3")
	
**************************************************
*Table F.3: Lineage Activity and Declaration of Independence: OLS Estimates
**************************************************

*Change this to your local directory*

cd "/Users/ywang/Dropbox/Book Project on State Building/Princeton UP/Replication Package/Appendices/data/"

set more off
	
use "Late Qing data.dta", clear

local controls "x y shape_area elevation slope dist_beijing_log dist_rivers_log dist_coast_log pass_qing_courier pop_den_1820 rice_ir"

xi: reg independence genealogy_IHS if periodid==6, cl(countyid)
estimates store independence1
estadd ysumm

xi: reg independence genealogy_IHS i.prefectureid if periodid==6, cl(countyid)
estimates store independence2
estadd ysumm

xi: reg independence genealogy_IHS `controls' i.prefectureid if periodid==6, cl(countyid)
estimates store independence3
estadd ysumm

xi: reg independence genealogy_IHS quota `controls' i.prefectureid if periodid==6, cl(countyid)
estimates store independence4
estadd ysumm

esttab independence1 independence2 independence3 independence4 using independence.tex, ///
	replace fragment keep(genealogy_IHS quota) ///
	b(3) se(3) posthead(\cmidrule(lr){2-5}) ///
	cells(b(star fmt(3)) se(fmt(3) par)) staraux star(* 0.10 ** 0.05 *** 0.01) collabels(none) ///
	label booktabs noconstant obslast nodepvars nomtitles nolines gaps ///
	scalars("r2 \(R^{2}\)") sfmt(3) ///
	stats(ymean ysd N r2, fmt(3 3 0 3) labels("Outcome mean" "Outcome std.dev." "Observations" "R2")) ///
	indicate("Prefectural FE = *Iprefectur*" "County-level controls = x")
	
	
